import threading
import time

import pygame
from PyQt5.QtCore import QThread
from pygame.sprite import AbstractGroup

import utils
from data import color, config, moveRole

i = 0


class Move(QThread):
    def __init__(self):
        super().__init__()
        self.isRun = True

    @staticmethod
    def run():
        global i
        while i < 5:
            print(i)
            time.sleep(1)
            i += 1


class Player(pygame.sprite.Sprite):
    def __init__(self, *groups: AbstractGroup):
        super().__init__(*groups)
        self.image = pygame.surface.Surface(config['playerSize'])
        self.image.fill(color["green"])
        self.rect = self.image.get_rect()
        self.direction = "right"
        self.time = 0

        def console():
            while True:
                print(threading.enumerate())
                time.sleep(1)

        t = threading.Thread(target=Move.run, daemon=True)
        t2 = threading.Thread(target=console, daemon=True)
        t.start()
        t2.start()
        # self.thread.start()

        utils.registerUpdate("player move", self.move)

    def move(self, dt):
        self.time += dt
        if self.direction == "left":
            self.rect.x -= 1
        if self.direction == "right":
            self.rect.x += 1
        if self.direction == "up":
            self.rect.y += 1
        if self.direction == "down":
            self.rect.y -= 1
        # print(self.direction)
